package SampleCollection.SampleCollection;

import java.util.Comparator;

//import com.keane.nclass.Character;

/*
 *Kid.java
 */
/**
 * @author Ridhav
 * 
 */
public class Kid implements Comparable {
	int age;

	String name;

	static String schoolName = "Gurukul";

	//static members are used with help of class.member name
	Kid() {
		age = 1;
		name = "shaitaan";

	}

	public Kid(int age, String name) {
		this.age = age;
		this.name = name;

	}

	public static void getSchool() {
		System.out.println("school is  : " + schoolName);
		Kid k = new Kid();
		//cant use directly
		//System.out.println("age is "  +age);
		System.out.println("age is " + k.age);
	}

	//because we willl use this pointe
	/*	Kid(int a,String n ){
	 age=a;
	 name=n;
	 
	 }*/

	// no need as this can be done with constructor
	/*public void setKid()	{
	 age=41;
	 name="shaitaan";
	 }
	 
	 public void setKid(int a, String n)	{
	 age=a;
	 name=n;
	 }*/

	public String toString() {

		return new StringBuffer("name : ").append(name).append(" age : ")
				.append(age).toString();
	}

	public void getKid() {
		System.out.println("age is " + age);
		System.out.println("name is " + name);
		System.out.println("school is  : " + schoolName);
	}

	public static String getSchoolName() {
		return schoolName;
	}

	public static void setSchoolName(String schoolName) {
		Kid.schoolName = schoolName;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public boolean equals(Object anObject) {

		if (anObject instanceof Kid) {
			Kid temp = (Kid) anObject;
			if (this.name.equals(temp.name) && this.age == temp.age)
				return true;
			else
				return false;
		} else
			return false;

	}
	

public int compareTo(Object o) {
		if(o instanceof Kid) {
			Kid temp1 = (Kid)o;
		
		  if(this.age>temp1.age)
			  return 1;
		  else
			  return 0;
		}
		return 0;
			
			}






//anonymous classes


public static Comparator cmpname=new Comparator()	{

	public int compare(Object o1, Object o2) {
		// TODO Auto-generated method stub
		Kid temp1 = (Kid)o1;
		Kid temp2=(Kid)o2;
	return temp1.name.compareTo(temp2.name);
	}
	
};

public static Comparator cmpage=new Comparator()	{

	public int compare(Object o1, Object o2) {
		
		Kid temp1 = (Kid)o1;
		Kid temp2=(Kid)o2;
		return temp1.age-temp2.age;
		  
		
	
	}
	
};

public int hashCode() {
	
	
	int result=17;
	result=37*result+this.name.hashCode();
	result=37*result+this.age;
		return result;
	
	
	
}



}

